/*
 * @Description: 生产配置
 * @Author: chenjiaxin
 * @Date: 2024-10-28 10:06:21
 * @LastEditTime: 2024-10-31 13:59:33
 */
const { merge: WebpackMerge } = require("webpack-merge");
const baseConfig = require("./webpack.config.base");
const CssMinimizerWebpackPlugin = require("css-minimizer-webpack-plugin");
const TerserWebpackPlugin = require("terser-webpack-plugin");

const prodConfig = {
  mode: "production",
  optimization: {
    minimizer: [
      new CssMinimizerWebpackPlugin(),
      new TerserWebpackPlugin({
        parallel: true, // 多进程并发压缩
        terserOptions: {
          sourceMap: false,
          compress: {
            warnings: true, // 去除warning警告
            // drop_debugger: true,// 发布时去除debugger语句
            drop_console: true, // 发布时去除console语句
            pure_funcs: ['console.log'] // 配置发布时，不被打包的函数
          }
        }
      }),
    ],
    splitChunks: {
      chunks: "all",
      cacheGroups: {
        vendor: {
          test: /[\\/]node_modules[\\/]/,
          filename: 'vendor.[contenthash:8].bundle.js'
        },
      },
    }
  }
};
module.exports = (env) => {
  // 设置环境参数
  if(env.production) {
    process.env.NODE_ENV = "production";
  }
  return WebpackMerge(baseConfig(), prodConfig)
}